package com.atguigu.gulimall.order.web;

import com.atguigu.gulimall.order.config.MyMqConfig;
import com.atguigu.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Controller
public class IndexController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("{page}.html")
    public String page(@PathVariable("page") String page) {
        return page;
    }


    @ResponseBody
    @GetMapping("/test")
    public String test() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(MyMqConfig.ORDER_EVENT_EXCHAGE, MyMqConfig.DELAY_QUEUE_ROUTINGKEY, orderEntity);
        return "ok";
    }
}
